/**
 * xxx 模型
 */

'use strict';

var mongodb = require('../mongodb.js');
var Schema = mongodb.Schema;

// create a schema
var ModelSchema = new Schema({
    email: {type: String, require: true, unique: true, index: true},
    name: {type: String, require: true},
    password: String,
    role: String,
    createdAt: Date,
    updatedAt: {type: Date, default: Date.now}
});

ModelSchema.pre('save', function (next) {
    if (!this.createdAt) {
        this.createdAt = new Date();
    }
    next();
});


// 指定collection name，默认是复数
var vendor = mongodb.model('user', ModelSchema, 'user');
exports = module.exports = vendor;